package com.xiaolin.Thread.pool;

import java.util.concurrent.*;

/**
 * @ClassName NewFixedThreadPoolTest
 * @Description 固定线程数的线程池
 * @Detail detail
 * @Author MyPC
 * @Date 2020/12/1
 * @Version 1.0
 */
public class NewFixedThreadPoolTest {
    public static void main(String[] args) {
        ExecutorService service = getNew1();
        service.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println("hello");
            }
        });
        service.shutdown();
    }

    /**
     * 第一种方式
     * @return
     */
    public static ExecutorService getNew1(){
        return new ThreadPoolExecutor(10,10,1, TimeUnit.MINUTES,new LinkedBlockingDeque<>());
    }

    /**
     * 第二种方式
     * @return
     */
    public static ExecutorService getNew2(){
        return new ThreadPoolExecutor(10,10,1, TimeUnit.MINUTES,new LinkedBlockingDeque<>(),Executors.defaultThreadFactory());
    }

    /**
     * 方式3，创建线程数为10的线程池
     * @return
     */
    public static ExecutorService getNew3(){
        return Executors.newFixedThreadPool(10);
    }

    /**
     * 方式3，创建线程数为10的线程池
     * @return
     */
    public static ExecutorService getNew4(){
        return Executors.newFixedThreadPool(10,Executors.defaultThreadFactory());
    }

}
